/**
 * create by young (young2f@outlook.com) on 2024/4/21
 */
'use strict';
const base = require('../base/controllerBase');
const _service = 'inboundService';

class InboundController extends base {
  async createInboundLot() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;
      const model = {
        tenantCode: { type: 'string' },
        code: { type: 'string' },
        lotCode: { type: 'string' },
      };

      ctx.validate(model, body);

      const result = await service[_service].createInboundLot(body);
      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }

  async deleteInboundLot() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;

      const model = {
        tenantCode: { type: 'string' },
        lotCode: { type: 'string' },
        pmLotId: { type: 'string' },
        inboundCount: { type: 'number' },
      };
      console.log('deletee', body);
      ctx.validate(model, body);

      const result = await service[_service].deleteInboundLot(body);
      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }

  async findInboundLotMany() {
    const { ctx, service } = this;
    try {
      const { body } = ctx.request;

      const model = {
        tenantCode: { type: 'string' },
        //  code: { type: 'string' },
      };

      ctx.validate(model, body);

      const result = await service[_service].findInboundLotMany(body);
      ctx.body = result;
      ctx.status = 200;
    } catch (e) {
      console.error(e);
      const _message = e && e.message ? e.message : this.ERROR_MSG;
      ctx.body = { status: 'error', message: _message, result: e };
      ctx.status = 200;
    }
  }


  // async updateOne() {
  //   const { ctx, service } = this;
  //   try {
  //     const { body } = ctx.request;
  //     const model = {
  //       tenantCode: { type: 'string' },
  //       code: { type: 'string' },
  //     };
  //
  //     ctx.validate(model, body);
  //
  //     const result = await service[_service].updateOne(body);
  //     ctx.body = result;
  //     ctx.status = 200;
  //   } catch (e) {
  //     console.error(e);
  //     const _message = e && e.message ? e.message : this.ERROR_MSG;
  //     ctx.body = { status: 'error', message: _message, result: e };
  //     ctx.status = 200;
  //   }
  // }
  //
  //
  // async findOne() {
  //   const { ctx, service } = this;
  //   try {
  //     const { body } = ctx.request;
  //     const model = {
  //       tenantCode: { type: 'string' },
  //     };
  //
  //     ctx.validate(model, body);
  //     body.isDeleted = false;
  //     const result = await service[_service].findOne(body);
  //
  //     ctx.body = result;
  //     ctx.status = 200;
  //   } catch (e) {
  //     console.error(e);
  //     const _message = e && e.message ? e.message : this.ERROR_MSG;
  //     ctx.body = { status: 'error', message: _message, result: e };
  //     ctx.status = 200;
  //   }
  // }
  //
  // async findMany() {
  //   const { ctx, service } = this;
  //   try {
  //     const { body } = ctx.request;
  //     const model = {
  //       tenantCode: { type: 'string' },
  //     };
  //
  //     ctx.validate(model, body);
  //     body.isDeleted = false;
  //     const result = await service[_service].findMany(body);
  //     ctx.body = result;
  //     ctx.status = 200;
  //   } catch (e) {
  //     console.error(e);
  //     const _message = e && e.message ? e.message : this.ERROR_MSG;
  //     ctx.body = { status: 'error', message: _message, result: e };
  //     ctx.status = 200;
  //   }
  // }

}

module.exports = InboundController;
